#version 460

layout (location = 0) in vec3 inPosition;
layout (location = 1) in vec3 inNormal;
layout (location = 2) in vec3 inTangent;
layout (location = 3) in vec2 inTexcoord;

layout (location = 0) out vec3 worldPosition;
layout (location = 1) out vec3 worldNormal;
layout (location = 2) out vec3 worldTangent;
layout (location = 3) out vec2 outTexcoord;
layout (location = 4) out vec4 clipSpacePosition;
layout (location = 5) out vec4 prevClipSpacePosition;

layout (binding = 0) uniform PerFrameUBO
{
    mat4 viewInverse;
    mat4 projInverse;
    mat4 projViewInverse;
    mat4 prevProjView;
    mat4 projView;
    vec4 cameraPosition;
    vec4 currentPrevJitter;
} perFrameUBO;

layout (push_constant) uniform PushConstants
{
    mat4 model;
    mat4 prevModel;
    uint objectIndex;
    float roughnessMultiplier;
} pushConstants;

void main() 
{
    vec4 worldPos = pushConstants.model * vec4(inPosition, 1.0);
    vec4 prevWorldPos = pushConstants.prevModel * vec4(inPosition, 1.0);

    gl_Position = perFrameUBO.projView * worldPos;

    worldPosition = worldPos.xyz;

    clipSpacePosition = gl_Position;
    prevClipSpacePosition = perFrameUBO.prevProjView * prevWorldPos;

    outTexcoord = inTexcoord;

    mat3 normalMat = mat3(pushConstants.model);
        
    worldNormal = normalMat * inNormal;
	worldTangent = normalMat * inTangent;
}